package unicall.em.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import unicall.em.models.SipAccount;
/**
 * SipAccountDao
 * @author jinchaoyang
 */
public interface SipAccountRepository extends JpaRepository<SipAccount, String>,JpaSpecificationExecutor<SipAccount> {
   
    @Modifying
    @Query("update SipAccount a set a.status='UNUSE' where a.clientNumber = :clientNumber")
    public int releaseAccount(@Param("clientNumber") String clientNumber);
    
    @Modifying
    @Query("update SipAccount a set a.agentId=:agentId where a.clientNumber= :clientNumber")
    public int bind(@Param("clientNumber")String clientNumber,@Param("agentId")String agentId);

    @Modifying
    @Query("update SipAccount a set a.agentId = null where a.clientNumber=:clientNumber")
    public int unbind(@Param("clientNumber")String clientNumber);
    
}
